package com.example.zhinongbao.fragment;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;


import com.example.zhinongbao.R;
import com.example.zhinongbao.database.DBHelper;


public class RegisterActivity extends AppCompatActivity {
    private EditText et_username,et_password,et_phone,et_paypassword;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);
        //获取mSharedPreferences
        et_phone = findViewById(R.id.et_phone);
        et_username = findViewById(R.id.et_username);
        et_password = findViewById(R.id.et_password);
        et_paypassword =findViewById(R.id.et_paypassword);
        //点击注册
        findViewById(R.id.toolbar).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();

            }
        });
        //点击注册
        findViewById(R.id.register).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String username = et_username.getText().toString();
                String password = et_password.getText().toString();
                String phone =et_phone.getText().toString();
                String paypassword =et_paypassword.getText().toString();
                if (TextUtils.isEmpty(username) && TextUtils.isEmpty(password)&& TextUtils.isEmpty(paypassword)) {
                    Toast.makeText(RegisterActivity.this, "请输入用户名或密码", Toast.LENGTH_SHORT).show();
                } else if (TextUtils.isEmpty(phone)){
                    Toast.makeText(RegisterActivity.this, "请输入手机号", Toast.LENGTH_SHORT).show();
                }else if (TextUtils.isEmpty(paypassword)){
                    Toast.makeText(RegisterActivity.this, "请输入支付密码", Toast.LENGTH_SHORT).show();
                }
                else {
                    int row = DBHelper.getInstance(RegisterActivity.this).register(username, password, phone,paypassword);
                    if (row > 0) {
                        Toast.makeText(RegisterActivity.this, "注册成功，请登录", Toast.LENGTH_SHORT).show();
                        finish();
                    }

                    //一定要提交


                }
            }
        });
    }
}
